﻿using Common.util;
using log4net;
using Quartz;
using StockIndex.service;

namespace StockIndex
{
    class TaskConfig
    {
        private static readonly ILog Log = LogManager.GetLogger(typeof(TaskConfig));
        public static void RunTask()
        {
            Log.Info("task init");
            QuartzUtils.Cron<SimpleIndicatorTask>("*/5 * * * * ?");
            QuartzUtils.Cron<SimpleIndicatorTask>("*/5 * * * * ?");
            QuartzUtils.Cron<TopicZdfCalculatorTask>("*/3 * * * * ?");
            QuartzUtils.Cron<StockZdfCalculatorTask>("*/3 * * * * ?");
            QuartzUtils.Cron<TopicZhangSuCalculatorTask>("*/3 * * * * ?");
            QuartzUtils.Cron<TdxDailyKLineTask>("0 10 8,9 * * ?");
            QuartzUtils.Cron<LiangbiCalculatorTask>("0 */1 * * * ?");
        }

        public static void Destroy()
        {
            Log.Info("task destroy");
            QuartzUtils.GetInstance().Destory();
        }
            
    }
    
    [DisallowConcurrentExecution]
    public class TopicZhangSuCalculatorTask:IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            ZhangSuService.CalculateTopicZhangSu();
        }
    }
     
    [DisallowConcurrentExecution]
    public class TopicZdfCalculatorTask:IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            ZdfService.CalculateTopicZdf();
        }
    }
    
    [DisallowConcurrentExecution]
    public class StockZdfCalculatorTask:IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            ZdfService.CalculateStockZdf();
        }
    }
    
    [DisallowConcurrentExecution]
    public class SimpleIndicatorTask:IJob
    { 
        private static readonly ILog Log = LogManager.GetLogger(typeof(SimpleIndicatorTask));
        public void Execute(IJobExecutionContext context)
        {
            Log.Info(" update simpleIndicator");
            SimpleIndicatorService.UpdateSimpleIndicator();
        }
    }
    
    [DisallowConcurrentExecution]
    public class TdxDailyKLineTask : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            TdxDailyKLineService.FullLastestDailyKLines();
            ZdfService.FullMultiPreviewTopicZdf();
        }
    }
    
    [DisallowConcurrentExecution]
    public class LiangbiCalculatorTask:IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            LiangbiService.CalcLiangbi();
        }
    }
}
